﻿
function GetBrands(categoryId, objControl, defaultValue, callback) {
    $("#" + objControl).empty();
    $("#" + objControl).append("<option value=\"\">--选择品牌--</option>");
    if (categoryId == "") {
        return;
    }
    var url =  "/Manage/AS/GoodsCommon.aspx?action=GetBrandsByCategory&CategoryID=" + categoryId;
    $.ajax(
    {
        type: "Get",
        url: url,
        dataType: "json",
        success: function (data) {
            var options = "";
            if (data != null) {
                var isHave = false;
                for (var i = 0; i < data.length; ++i) {
                    if (defaultValue == data[i]._id) {
                        options += "<option value=\"" + data[i]._id + "\" Selected>" + data[i]._name + "</option>";
                        isHave = true;
                    }
                    else
                        options += "<option value=\"" + data[i]._id + "\">" + data[i]._name + "</option>";
                }
            }
            else {
                $("#" + objControl).empty();
                options += "<option value=\"\">--无品牌信息--</option>";
            }
            $("#" + objControl).append(options);

            if (!isHave && callback != null)
                callback();

        }
    });
}